

/**
 * 是否有权限
 * @param {*} key
 */
export function isAuth(key) {
    //console.log('按钮权限验证 -------------- ', key);

    var dangQianPath = this.$route.path;

    //console.log('this.$route', this.$route);
    //console.log('this.$route.path', dangQianPath);


    const matched = this.$route.matched;
    // =============================================================================
    var menu = GetRouteMenu(dangQianPath, matched);
    //console.log('menu', menu);
    //console.log('menu', menu.children);
    // =============================================================================

    for (let i = 0; i < menu.children.length; i++) {
        if (menu.children[i] != null) {
          
            if (menu.children[i].Func == key) {
                console.log('Btn', menu.children[i]);
                return menu.children[i].IsHide || true;
            }
        }
    }

    var btnAuth = localStorage.getItem('router').indexOf(key) !== -1;
    return btnAuth || false;
}


/**
 * 根据当前页和路由
 * 分析当前路由信息
 * ***/
function GetRouteMenu(dangQianPath, matched) {

    let routers = JSON.parse(localStorage.getItem('router'));
    let rObj = null;
    for (let i = 0; i < matched.length; i++) {
        routers = routers.filter((v) => {
            if (v.children != null) {
                for (let menu = 0; menu < v.children.length; menu++) {
                    if (v.children[menu] != null) {
                        // console.log(dangQianPath, v.children[menu].path);
                        if (v.children[menu].path == dangQianPath) {

                            rObj = v.children[menu];
                            return rObj;
                        }
                    }
                }
            }
        })
    }
    return rObj;
}
